<?php
// +----------------------------------------------------------------------
// | OneThink [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: yangweijie <yangweijiester@gmail.com> <code-tech.diandian.com>
// +----------------------------------------------------------------------

namespace Help\Model;
use Think\Model;

/**
 * Class HelpAskModel  求帮忙模型
 * @package Help\Model
 * @author:xjw129xjt xjt@ourstu.com
 */
class HelpAskModel extends Model {

    protected $tableName='help_ask';

    protected $_auto = array(
        array('create_time', NOW_TIME, self::MODEL_INSERT),
        array('update_time', NOW_TIME, self::MODEL_BOTH),
        array('status', '1', self::MODEL_INSERT),
    );

    protected $insertFields = 'to_uid,from_uid,content,help_id'; // 新增数据的时候允许写入name和email字段
    protected $updateFields = 'to_uid,from_uid,content,help_id'; // 编辑数据的时候只允许写入email字段

    public function addHelpAsk($data){
        $data = $this->create($data);
        $res = $this->add($data);
        return $res;
    }

    public function getAsk($map=''){
        $map['status'] =1;
        $ask = $this->where($map)->order('create_time desc')->select();
        return $ask;
    }
    public function getPage($map='',$page=1,$r=20,$order='id desc'){
        $map['status']=1;
        $help_list = $this->where($map)->order($order)->page($page,$r)->select();
        foreach($help_list as &$v){
            $v['from_user'] =query_user(array('uid', 'username', 'nickname', 'space_url', 'space_link', 'avatar64','avatar128', 'rank_html', 'signature','address','doing','fans'), $v['from_uid']);
            $v['to_user'] =query_user(array('uid', 'username', 'nickname', 'space_url', 'space_link', 'avatar64','avatar128', 'rank_html', 'signature','address','doing','fans'), $v['to_uid']);
            $v['help'] =D('Help/Help')->getHelp($v['help_id']);
        }
        unset($v);
         return $help_list;
    }

}